package com.awangyh.jdk8.jsoup;

import org.jsoup.helper.StringUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by admin on 2017/4/11.
 */
public enum IntegrityType {
	OTHER("0", "其它", "其它"),
    IS_LOST_CONTACT_MECHANISM("1", "失联(异常)", "失联机构"),
    IDENTIFICATION("2", "异常机构", "异常机构"),//小心， tab键不能去掉，比较恶心
    SHAM_STATEMENT("3", "虚假填报", "虚假填报"),
    MATER_RIAL_OMISSION("4", "重大遗漏", "重大遗漏"),
    EIGHT_LINE("5", "违反八条底线内容", "违反八条底线"),
    BAD_CREDIT("6", "相关主体存在的不良诚信记录", "相关主体存在不良诚信记录");

	private static final List<IntegrityType> MATCH_VALUES = new ArrayList<>();

	static {
        MATCH_VALUES.add(BAD_CREDIT);
        MATCH_VALUES.add(MATER_RIAL_OMISSION);
        MATCH_VALUES.add(EIGHT_LINE);
        MATCH_VALUES.add(SHAM_STATEMENT);
        MATCH_VALUES.add(IS_LOST_CONTACT_MECHANISM);
        MATCH_VALUES.add(IDENTIFICATION); //恶心，不能改变，“异常机构“名称会出现在前面的列表，所以放在最后
	}

	private String code;

	private String key;

	private String name;

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	private IntegrityType(String code, String key, String name) {
		this.code = code;
		this.key = key;
		this.name = name;
	}

	public static List<IntegrityType> getIntegrityType(String value) {
		if (StringUtil.isBlank(value)) return Collections.singletonList(OTHER);

		List<IntegrityType> list = MATCH_VALUES.stream().filter(it -> value.contains(it.getKey())).collect(Collectors.toList());
		return list == null || list.isEmpty() ? Collections.singletonList(OTHER) : list;
	}

    public static List<String> selectIntegrityType(String value) {
        List<IntegrityType> list = getIntegrityType(value);
        if ( list == null || list.isEmpty() ) {
            return Collections.singletonList(OTHER.getCode());
        }

        List<String> sList = new ArrayList<>();
        list.stream().forEach(it -> sList.add(it.getCode()));
        return sList;
    }

}
